// Array2D template class
// Created by Administrator on 2021/8/30.
//

#ifndef BOXPUSHER_ARRAY2D_H
#define BOXPUSHER_ARRAY2D_H

template<typename T>
class Array2D
{
public:
    Array2D() : w_{0}, h_{0}, data_{nullptr} {}
    ~Array2D()
    {
        delete[] data_;
        data_ = nullptr;
    };

    void setSize(unsigned int w, unsigned int h)
    {
        w_ = w;
        h_ = h;
        data_ = new T[w_ * h_];
    }

    unsigned int w() const { return w_; }
    unsigned int h() const { return h_; }

    T& operator() (unsigned int x, unsigned int y) { return data_[w_ * y + x]; }
    const T& operator() (unsigned int x, unsigned int y) const { return data_[w_ * y + x]; }

private:
    T* data_;
    unsigned int w_;
    unsigned int h_;
};

#endif //BOXPUSHER_ARRAY2D_H
